/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.free.ts.contact;

import be.free.ts.support.AbstractPersistable;
import be.free.ts.support.validation.Ssin;
import org.eclipse.persistence.annotations.Convert;
import org.joda.time.LocalDate;

import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @author Christophe De Blende
 */
@Entity
public class Contact extends AbstractPersistable {

	@NotNull
	@Ssin
	private String ssin;

	@NotNull
	@Size(min = 3, max = 80)
	private String lastName;

	@NotNull
	@Size(min = 3, max = 80)
	private String firstName;

	@Past
	@NotNull
	@Temporal(TemporalType.DATE)
	@Convert("LocalDateConverter")
	private LocalDate birthDate;

	protected Contact() {
	}

	public String getSsin() {
		return ssin;
	}

	public void setSsin(String ssin) {
		this.ssin = ssin;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public LocalDate getLocalBirthDate() {
		return birthDate;
	}

	public void setLocalBirthDate(LocalDate birthDate) {
		this.birthDate = birthDate;
	}

	public Date getBirthDate() {
		if (birthDate == null) {
			return null;
		}
		return birthDate.toDate();
	}

	public void setBirthDate(Date date) {
		this.birthDate = date == null ? null : LocalDate.fromDateFields(date);
	}

}
